<?php
namespace app\admin\logic;

//分类页
use think\facade\Request;

class GcategoryLogic{
    //where拼装查询条件 方法
    public static function reformData(){
        //接参
        $param=Request::param();
        //判断是否传parent_id,默认给0
        $parent_id = isset($param['parent_id'])?$param['parent_id']:0;
        $data=[
            'parent_id'=>$parent_id,
        ];
        //拼装where条件 第一个where
        $where[]=['parent_id','=',$parent_id];
        return $where;
    }
        //查询最后一个分类不能点跳页
    public  static function setCateNext($cate){
        //查询所有的id值
        $parent_id_all=\app\admin\model\Gcategory::getParentIdAll();
        //array_unique删除重复的值
        $parent_id_all=array_unique($parent_id_all);
        foreach ($cate as &$v){
//           foreach ($parent_id_all as $s){
//               if ($v['cate_id']==$s){
//                   $v['next_cate']=1;
//               }
//           }
            //判断$v['cate_id']在不在数组里
            if (in_array($v['cate_id'],$parent_id_all)){
                $v['next_cate']=1;
            }
        }

        return $cate;
    }

    //分类添加
     public static function   cateAddInfo($post){
         $if_show=isset($post['if_show'])?$post['if_show']:'';
         $xiaoguo=isset($post['xiaoguo'])?$post['xiaoguo']:'';
        $data=[
                'cate_name'=>$post['name'],
                'parent_id'=>$post['parentid'],
                'sort_order'=>$post['sort'],
                'if_show'=>$if_show,
                'xiaoguo'=>$xiaoguo

        ];
        return $data;

         }
     //分类修改
     public static function   cateEditInfo($post){
         $if_show=isset($post['if_show'])?$post['if_show']:'';
         $xiaoguo=isset($post['xiaoguo'])?$post['xiaoguo']:'';
         $data=[
             'cate_id'=>$post['cid'],
             'cate_name'=>$post['name'],
             'parent_id'=>$post['parentid'],
             'sort_order'=>$post['sort'],
             'if_show'=>$if_show,
             'xiaoguo'=>$xiaoguo

         ];
         return $data;



         }





}